repo: Make repo/tmp expiry configurable via tmp-expiry-seconds
authorColin Walters <walters@verbum.org>
Mon, 21 Mar 2016 21:54:45 +0000 (17:54 -0400)
committerColin Walters (automation) <walters+githubbot@verbum.org>
Mon, 2 May 2016 18:44:44 +0000 (18:44 +0000)
We were arbitrarily only deleting content after exactly one day.  Some
use cases may want something else; make it configurable.

Closes: #170
Approved by: jlebon

src/libostree/ostree-repo-commit.c
src/libostree/ostree-repo-private.h
src/libostree/ostree-repo.c

index 0d7f9bee6e36607464c9066ddd772c3760542f7c..60eb6260ac7ca2e7a51585e3a71e521d811764c2 100644 (file)
@@ -1349,11 +1349,12 @@ cleanup_tmpdir (OstreeRepo        *self,
           if (stbuf.st_mtime > curtime_secs)
             continue;
 
-          /* Now, we arbitrarily delete files/directories older than a
-           * day, since that's what we were doing before we had locking.
+          /* Now, we're pruning content based on the expiry, which
+           * defaults to a day.  That's what we were doing before we
+           * had locking...but in future we can be smarter here.
            */
           delta = curtime_secs - stbuf.st_mtime;
-          if (delta > 60*60*24)
+          if (delta > self->tmp_expiry_seconds)
             {
               if (!glnx_shutil_rm_rf_at (dfd_iter.fd, dent->d_name, cancellable, error))
                 goto out;
index 273edd1ac94e424abcd456fe2c3c936b4ff659b0..3d59d911ceda7d9229993952303ab8eef6170b33 100644 (file)
@@ -98,6 +98,7 @@ struct OstreeRepo {
   OstreeRepoMode mode;
   gboolean enable_uncompressed_cache;
   gboolean generate_sizes;
+  guint64 tmp_expiry_seconds;
 
   OstreeRepo *parent_repo;
 };
index 2c9a7fd32834e757f8291e99f69f219c54c1fede..15452c430675b1ed7a534b39f78051c78d481c2d 100644 (file)
@@ -2561,6 +2561,16 @@ ostree_repo_open (OstreeRepo    *self,
       ostree_repo_set_disable_fsync (self, TRUE);
   }
 
+  { g_autofree char *tmp_expiry_seconds = NULL;
+
+    /* 86400 secs = one day */
+    if (!ot_keyfile_get_value_with_default (self->config, "core", "tmp-expiry-secs", "86400",
+                                            &tmp_expiry_seconds, error))
+      goto out;
+
+    self->tmp_expiry_seconds = g_ascii_strtoull (tmp_expiry_seconds, NULL, 10);
+  }
+
   if (!append_remotes_d (self, cancellable, error))
     goto out;